import requests

ip = "http://192.168.178.128:8080"
loginData={"username":"admin","password":"123456"}
s = requests.post(f"{ip}/login",data=loginData)
# print(s)
# print(s.json())
#获取token
token = s.json()["Admin-Token"]
#接口请求，传值
# #get，url后面 传给params传给data
# #post x-www-form
# form-data 普通传给data特殊传给files
#json   传给json

#调用token
header = {"Admin-Token":token}

#上传文件
addfileData = {"type":"img"}
fname = r"C:\Users\30644\Desktop\tp.jpg"
fData = {"file":("tp.jpg",open(fname,"rb"),"image/png")}
s1 = requests.post(f"{ip}/file/upload",data=addfileData,headers=header,files=fData)
# print(s.json())

#新增日志
bid = s1.json()['batchId']
addLogData = {"categoryId":"1","content":"今日内容~~","tomorrow":"明日工作计划~","question":"今日遇到的问题","batchId":bid,"sendUserIds":"3,4"}
s2 = requests.post(f"{ip}/OaLog/addOrUpdate",json=addLogData,headers=header)
# print(s2)
# print(s2.json())

#查询
getLogData = {"page":1,"limit":5,"by":"1"}
s = requests.post(f"{ip}/OaLog/queryList",data=getLogData,headers=header)
# print(s)
# print(s.json())
b_id = s.json()["data"]["list"][0]["logId"]

#修改
modifyData = {"logId":b_id,"categoryId":"1","content":"修改后","tomorrow":"修改后","question":"修改后","batchId":bid,"sendUserIds":"3,4"}
s3 = requests.post(f"{ip}/OaLog/addOrUpdate",json=modifyData,headers=header)
print(s3)
print(s3.json())

#删除
delLogData = {"logId":b_id}
s4 = requests.post(f"{ip}/OaLog/deleteById",data=delLogData,headers=header)
print(s4)
print(s4.json())